package isSymmetric101;


public class IsSymmetric {

    public boolean isSymmetric(TreeNode root) {
        return compare(root,root);
    }


    public boolean compare(TreeNode left,TreeNode right){
        if((left == null)&&(right!=null)){
            return false;
        }
        if((left != null)&&(right==null)){
            return false;
        }
        if((left == null)&&(right==null)){
            return true;
        }
        if(left.val != right.val){
            return false;
        }

        boolean outSide = compare(left.left, right.right);
        boolean inside = compare(left.right, right.left);
        return outSide && inside;

    }
}


class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}